package net.siufung.market.base.user.config;

import lombok.AllArgsConstructor;
import net.siufung.market.base.dept.api.IDeptUserApi;
import net.siufung.market.base.permit.spi.IRoleUserCountSpi;
import net.siufung.market.base.tenant.api.ITenantUserApi;
import net.siufung.market.base.user.mapper.IUserMapper;
import net.siufung.market.base.user.mapper.IUserRoleMapper;
import net.siufung.market.base.user.provider.DeptUserProvider;
import net.siufung.market.base.user.provider.RoleUserCountProvider;
import net.siufung.market.base.user.provider.TenantUserProvider;
import net.siufung.market.base.user.service.IUserService;
import net.siufung.security.api.service.passwd.ILoginPasswdService;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

/**
 * @author 陈建峰
 * @since 2022/5/10 11:13 下午
 */
@Configuration
@MapperScan({"net.siufung.market.base.user.mapper"})
@AllArgsConstructor
public class MarketUserAutoConfig {

    private final IUserMapper userMapper;
    private final IUserService userService;
    private final IUserRoleMapper userRoleMapper;
    private final ILoginPasswdService loginPasswdService;

    @Bean
    @Primary
    public IDeptUserApi deptUserProvider(){
        return new DeptUserProvider(userMapper, userService);
    }

    @Bean
    @Primary
    public IRoleUserCountSpi roleUserCountProvider(){
        return new RoleUserCountProvider(userRoleMapper);
    }

    @Bean
    @Primary
    public ITenantUserApi tenantUserProvider(){
        return new TenantUserProvider(userService, userMapper, loginPasswdService);
    }

}
